const path = require('path');
const express = require('express');
const app = express();
const basePath = '/sole';
const bodyParser = require('body-parser');

// 加载静态文件 打包好的静态文件放在dist下
app.use(express.static(path.join(__dirname, './dist')));

app.use(bodyParser.urlencoded({ extended: false }));

app.get(`${basePath}/shop/*`, (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/shop.html'));
});

app.get(`${basePath}/shop`, (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/shop.html'));
});

app.get(`${basePath}/shop-order/*`, (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/shop.html'));
});

app.get(`${basePath}/error`, (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/redirect.html'));
});

// 浏览器调试地址
app.get(`${basePath}/set-cookie`, (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/redirect.html'));
});

// 公版小程序跳转链接
app.get(`${basePath}/bilin-mini-redirect`, (req, res) => {
    res.sendFile(path.join(__dirname, 'dist/redirect.html'));
});

// 健康检查
app.get(`${basePath}/health-check`, (req, res) => {
    res.send('ok');
});

const port = 6666;

//监听端口
app.listen(port, (err) => {
    if (err) {
        console.log(err);
        return null;
    }
    return console.log(`${port} port starting`);
});
